package com.stt.weather.base.scheduler;

import com.stt.weather.model.WeatherData;
import com.stt.weather.base.service.WeatherService;
import com.stt.weather.util.CityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 天气数据定时任务调度器
 * 负责定期获取天气数据并发送通知
 */
@Component
public class WeatherScheduler {

    /**
     * 天气服务对象
     */
    @Autowired
    private WeatherService weatherService;

    /**
     * 定时获取天气数据并发送通知
     * 每小时执行一次（3600000毫秒）
     */
//    @Scheduled(fixedRate = 3600000)
    public void fetchWeatherData() {
        // 这里可以从配置文件或数据库中读取需要监控的城市列表
        for (String city : CityUtil.getCodeList()) {
            // 获取天气数据
            WeatherData weatherData = weatherService.getWeatherData(city);

            // 发送通知
            weatherService.sendEmailNotification(weatherData);
            weatherService.sendSMSNotification(weatherData);
        }
    }
} 